#ifndef IRR_ENGINE_H
#define IRR_ENGINE_H

#include "iirlicht/irrlicht.h"
#pragma comment(lib, "iirlicht/Irrlicht.lib")
#ifndef _DEBUG
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif

//namespaces. I do not like these
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#include "Singleton.h"
#include <vector>


class IrrEngine
{
public:

	bool Init();
	bool Init(video::E_DRIVER_TYPE deviceType, int x, int y, int bits, bool fullscreen,bool stencilbuffer,bool vsync,IEventReceiver* receiver);
	void Draw();

	void Cleanup();

	//inline functions
	IrrlichtDevice* GetDevice() {return m_pDevice;}
	IVideoDriver* GetVideo() {return m_pDriver;}
	ISceneManager* GetScene() {return m_pSmgr;}
	IGUIEnvironment* GetGUI() {return m_pGuiEnv;}
	ICameraSceneNode* GetCamera(){return m_pCamera;}
	ICameraSceneNode* GetCamera(int id){return m_vCameras[id];}
	void SetCamera(ICameraSceneNode* c){m_pCamera=c; m_vCameras.push_back(c); m_pSmgr->setActiveCamera(m_pCamera);}
	void SetCamera(int i){m_pCamera = m_vCameras[i]; m_pSmgr->setActiveCamera(m_pCamera);}
	void AddCamera(ICameraSceneNode* c){m_vCameras.push_back(c);}

private:
	IrrEngine();
	friend class Singleton<IrrEngine>;

	IrrlichtDevice* m_pDevice;
	IVideoDriver* m_pDriver;
	ISceneManager* m_pSmgr;
	IGUIEnvironment* m_pGuiEnv;
	std::vector <ICameraSceneNode*> m_vCameras;
	ICameraSceneNode* m_pCamera;
};

//shortcuts for readability
typedef Singleton<IrrEngine> TheEngine;
#define TheDevice Singleton<IrrEngine>::Instance()->GetDevice()
#define TheVideo Singleton<IrrEngine>::Instance()->GetVideo() 
#define TheScene Singleton<IrrEngine>::Instance()->GetScene() 
#define TheGUI Singleton<IrrEngine>::Instance()->GetGUI() 
#define TheCamera Singleton<IrrEngine>::Instance()->GetCamera()

#endif //IRR_ENGINE_H